using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.XSchEmA.Entity;

namespace Pixysoft.Framework.XSchEmA.Sql
{
    internal class AccessSqlBuilder : ASqlBuilder
    {
        private AccessSqlBuilder() { }
        private static AccessSqlBuilder instance;
        public static AccessSqlBuilder Instance
        {
            get
            {
                if (instance == null)
                    instance = new AccessSqlBuilder();
                return instance;
            }
        }

        public string CreateDatabase(string databasename)
        {
            return null;
        }

        public string DropDatabase(string databasename)
        {
            return null;
        }

        public override string AlterTableModifyColumn(ColumnSchema column)
        {
            if (column == null)
                return null;
            StringBuilder builder = new StringBuilder();
            builder.Append("ALTER TABLE " + column.TableName + " ALTER \r\n");
            builder.Append(" " + column.ColumnName + "\t");
            builder.Append(GetDataType(column.DataType));
            builder.Append(CreateDefaultValue(column));
            //builder.Append(";");
            return builder.ToString();
        }

        public override string AlterTableModifyColumnNullable(ColumnSchema column)
        {
            if (column == null)
                return null;
            StringBuilder builder = new StringBuilder();
            builder.Append("ALTER TABLE " + column.TableName + " ALTER \r\n");
            builder.Append(" " + column.ColumnName + "\t");
            builder.Append(GetDataType(column.DataType));
            builder.Append(CreateStrongNullable(column));
            //builder.Append(";");
            return builder.ToString();
        }
        
        public string AlterTableModifyAutoIncColumn(ColumnSchema column)
        {
            if (column == null)
                return null;
            StringBuilder builder = new StringBuilder();
            builder.Append("ALTER TABLE " + column.TableName + " ALTER \r\n");
            builder.Append(" " + column.ColumnName + "\t");
            builder.Append("COUNTER");
            builder.Append(" NOT NULL");
            //builder.Append(";");
            return builder.ToString();
        }

        public override string AlterTableDropIndex(IndexSchema index)
        {
            if (index == null)
                return null;

            //DROP INDEX {0} ON {1}

            StringBuilder builder = new StringBuilder();

            builder.Append(string.Format("DROP INDEX {0} ON {1}",
                index.ConsName, index.TableName));

            return builder.ToString();

        }
    }
}
